package de.karlNet.sambamanager.view.beans.trees;

import javax.annotation.PostConstruct;

import org.primefaces.model.TreeNode;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope; import org.springframework.context.annotation.ScopedProxyMode;
import org.springframework.stereotype.Controller;

import de.karlNet.sambamanager.ldapController.ILdapTree;
import de.karlNet.sambamanager.ldapController.LdapMemberTree;
import de.karlNet.sambamanager.ldapModel.ITypeCheckerCallback;
import de.karlNet.sambamanager.ldapModel.LdapObject;
import de.karlNet.sambamanager.view.beans.ManualLeafHandlingTreeNode;
@Controller
@Scope(value="session", proxyMode=ScopedProxyMode.TARGET_CLASS)
public class LdapGroupBean extends AbstractTreeBean {
	@Autowired
	private LdapMemberTree ldapMemberTree;

	public LdapGroupBean() {
		super();
	}

	@Override
	protected ILdapTree getLdapTree() {
		return ldapMemberTree;
	}

	@Override
	public void expandAll() {
		this.reset();
		this.myRoot.setExpanded(true);
		for (TreeNode child : this.myRoot.getChildren()) {
			child.setExpanded(true);
			this.expandAll((ManualLeafHandlingTreeNode) child);
		}
	}

	@Override
	@PostConstruct
	public void reset() {
		super.reset();

		for (final LdapObject ldapObject : this.ldapMemberTree.getRootNodes()) {
			ldapObject.isType(new ITypeCheckerCallback() {
				public void isGroup() {
					new ManualLeafHandlingTreeNode("group", ldapObject, myRoot);
				}

				public void isUser() {
					new ManualLeafHandlingTreeNode("user", ldapObject, myRoot);
				}

				public void isNestable() {

				}

				public void isLdapObject() {
					new ManualLeafHandlingTreeNode("object",ldapObject, myRoot);
				}

				public void isContainer() {
					new ManualLeafHandlingTreeNode("container", ldapObject,
							myRoot);
				}
			});
		}
	}

}
